package com.joysuch.wwyt.bp.entity;

import com.joysuch.wwyt.core.support.AutoSetCommonFieldListener;
import lombok.Data;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.Date;

import static javax.persistence.GenerationType.IDENTITY;

@EntityListeners({AuditingEntityListener.class, AutoSetCommonFieldListener.class})
@Entity
@Table(name = "wwyt_bp_emergency_exercise_record")
@SQLDelete(sql = "update wwyt_bp_emergency_exercise_record set DELETE_FLAG = '1' where id= ?")
@SQLDeleteAll(sql = "update wwyt_bp_emergency_exercise_record set DELETE_FLAG = '1' where id= ?")
@Where(clause = "DELETE_FLAG = '0'")
@Data
@Proxy(lazy = false)
public class BpEmergencyExerciseRecord implements Serializable {

    //演练记录id
    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "ID", unique = true, nullable = false)
    private Long id;

    @Column(name = "name")
    private String name;

    //编码
    @Column(name = "CODE")
    private String code;

    //演练计划id
    @Column(name = "EP_ID")
    private Long epId;

    //演练名称
    @Column(name = "EP_NAME")
    private String epName;

    //演练日期
    @Column(name = "DATE")
    private LocalDate date;

    //演练实施人员
    @Column(name = "IMPLEMENTER_ID")
    private String implementerId;

    //主要参演人员
    @Column(name = "PARTICIPANT_ID")
    private String participantId;

    //其他参演部门
    @Column(name = "DEPART_ID")
    private String departId;

    //演练内容
    @Column(name = "CONTENT")
    private String content;

    //演练目的
    @Column(name = "GOAL")
    private String goal;

    //演练过程
    @Column(name = "PROCESS")
    private String process;

    //演练小结
    @Column(name = "SUMMARY")
    private String summary;

    //评价意见
    @Column(name = "OPINION")
    private String opinion;

    //需整改数量
    @Column(name = "ACCOUNT")
    private Integer account;

    //状态:0待整改;1已整改;2无需整改
    @Column(name = "STATE")
    private Integer state;

    //附件id
    @Column(name = "ATTACHMENT_ID")
    private String attachmentId;

    @org.springframework.data.annotation.CreatedBy
    @Column(name = "CREATE_BY")
    private Long createBy;

    @org.springframework.data.annotation.CreatedDate
    @Column(name = "CREATE_TIME")
    private Date createTime;

    @org.springframework.data.annotation.LastModifiedBy
    @Column(name = "UPDATE_BY")
    private Long updateBy;

    @org.springframework.data.annotation.LastModifiedDate
    @Column(name = "UPDATE_TIME")
    private Date updateTime;

    @Column(name = "DELETE_FLAG")
    private String deleteFlag;

    @Column(name = "ORG_CODE")
    private String orgCode;

    @Column(name = "TENENT_ID")
    private Long tenentId;

//    private BpEmergencyExercisePlan bpEmergencyExercisePlan;
//
//    @ManyToOne(fetch = FetchType.EAGER)
//    @JoinColumn(name = "EP_ID")
//    @NotNull(field = "应急演练计划")
//    public BpEmergencyExercisePlan getBpEmergencyExercisePlan() {
//        return this.bpEmergencyExercisePlan;
//    }
//
//    public void setBpEmergencyExercisePlan(BpEmergencyExercisePlan bpEmergencyExercisePlan) {
//        this.bpEmergencyExercisePlan = bpEmergencyExercisePlan;
//    }


    public int hashCode() {
        return new HashCodeBuilder().append(getId()).toHashCode();
    }

    public boolean equals(Object obj) {
        if (obj instanceof BpEmergencyExerciseRecord == false)
            return false;
        if (this == obj)
            return true;
        BpEmergencyExerciseRecord other = (BpEmergencyExerciseRecord) obj;
        return new EqualsBuilder().append(getId(), other.getId()).isEquals();
    }
}
